package com.zbcz.crm.fragment.marketmanager

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.zbcz.crm.MarketManagerActivity.Companion.PROJECT_ID
import com.zbcz.crm.adapter.FollowUpRecordAdapter
import com.zbcz.crm.databinding.FragmentCommonListBinding
import com.zbcz.crm.viewmodel.FollowupRecordViewModel

class FollowUpRecordFragment : Fragment() {

    private lateinit var binding: FragmentCommonListBinding

    private val mViewModel: FollowupRecordViewModel by viewModels()

    companion object {
        fun createFollowUpFragment(id: String): FollowUpRecordFragment {
            return FollowUpRecordFragment().apply {
                val args = Bundle()
                args.putString(PROJECT_ID, id)
                arguments = args
            }
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentCommonListBinding.inflate(inflater, container, false)
        init()
        return binding.root
    }

    fun init() {
        val id = arguments?.getString(PROJECT_ID)
        mViewModel.queryFollowRecord(id)
        mViewModel.mResult.observe(requireActivity()) {
            if (!it.isNullOrEmpty()) {
                binding.mList.adapter = it?.let { it1 -> FollowUpRecordAdapter(it1) }
                binding.emptyGroup.visibility = View.GONE
            } else {
                binding.emptyGroup.visibility = View.VISIBLE
            }
        }
    }
}